/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.Country;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author laverson
 */
@Stateless
public class CountryService extends GenericService<Country> {

    public CountryService() {
        super(Country.class);
    }
    
    @Override
    public void save(Country entity){
        super.save(entity);
    }
    
    @Override
    public void delete(Country entity){
        super.delete(entity);
    }
    
    @Override
    public void update(Country entity){
        super.update(entity);
    }
    
    @Override
    public Country find(Long id){
        return super.find(id);
    }
    
    @Override
    public List<Country> findAll(){
        return super.findAll();
    }
    
    public List<Country> autoComplete(String query){
        return findByName(query);
    }
    
    public List<Country> findByName(String query){
        List<Country> results = getEntityManager().createQuery("select e from " + Country.class.getSimpleName() + " e where lower(e.name) like '%" + query.toLowerCase().trim() + "%'").getResultList();
        return results;
    }
    
}
